/*
 * searchbycodesub.java
 *
 * Created on 16 ����Ҿѹ�� 2551, 13:20 �.
 */

package JavaProjectPackage;
import java.io.*;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;
/**
 *
 * @author  Administrator
 */
public class searchbycodesub extends javax.swing.JFrame {
    
    /** Creates new form searchbycodesub */
    public searchbycodesub() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 12));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("กรุณาใส่รหัสวิชา");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton1.setText("search");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton2.setText("close");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(109, 109, 109)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(57, 57, 57)
                        .addComponent(jButton2)))
                .addContainerGap(108, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(95, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(85, 85, 85))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO add your handling code here:
         if(jTextField1.getText().equals("11011")||jTextField1.getText().equals("11012")||
                     jTextField1.getText().equals("11013")||jTextField1.getText().equals("11014")||jTextField1.getText().equals("11015")||
                     jTextField1.getText().equals("11016")||jTextField1.getText().equals("11017")||jTextField1.getText().equals("11018")||
                     jTextField1.getText().equals("11019")||jTextField1.getText().equals("11020")){
              try {
            see();                                  
        } catch (IOException ex) {
            ex = null;}
         }else new subjecterror().setVisible(true);
    }//GEN-LAST:event_jButton1MouseClicked

    public void see() throws IOException{
      int j = 0,k=0,l=0,m=0,n=0,g=0;
      String n1="",n2="",n3="",n4="",n5="",chkID="",bb="",a="",aa="",aaa="",gg="";
    
    FileReader r = new FileReader("courseregis.txt");
 
       
        BufferedReader b = new BufferedReader(r);
      while((chkID=b.readLine())!=null){
       j=0;
       l++;
       k=0;
       bb="";
       aa="";
       aaa="";
  for(int i=0;i<chkID.length();i++){
    
       if(chkID.charAt(i)=='\t'){
      a = chkID.substring(j,i);
       j=i+1;   
       k++;
       if(k==1) bb=a;
       if(k==2) aa=a;
       if(k==3) aaa=a;
       }
  }
       if(jTextField1.getText().equals(aa)) {
      if(m==0) {n1=bb; m++; gg=aaa; System.out.println(m);}
      else if(m==1) {n2=bb; m++; System.out.println(m);}
      else if(m==2) {n3=bb; m++; System.out.println(m);}
      else if(m==3) {n4=bb; m++; System.out.println(m);}
      else if(m==4) {n5=bb; m++; System.out.println(m);}
  }
       
       }
        new detailbysub(n1,n2,n3,n4,n5,gg).setVisible(true);
      }
    
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO add your handling code here:
        setVisible(false);
    }//GEN-LAST:event_jButton2MouseClicked
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new searchbycodesub().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    
}
